using System;
using System.Collections.Generic;
using System.Text;
using BTV.Base;

namespace BTV.TVAnyTime
{
    public class TVAnySchedule : BTVSchedule
    {

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
        public override void SetStartTime(string time)
        {
            //2005-11-21T01:15:00Z
            String tYear = time.Substring(0,4);
            String tMonth = time.Substring(5,2);
            String tDay = time.Substring(8,2);
            String tHour = time.Substring(11,2);
            String tMin = time.Substring(14,2);
            StartTime = new DateTime(Int32.Parse(tYear), Int32.Parse(tMonth), Int32.Parse(tDay), Int32.Parse(tHour), Int32.Parse(tMin), 0);
            if (DateTime.Now != DateTime.UtcNow)
            {
                StartTime = StartTime.AddHours(1.0);
            }
        }

        public void SetStartTime(DateTime time)
        {
            if (DateTime.Now != DateTime.UtcNow)
            {
                time = time.AddHours(1.0);
            }
            StartTime = time;
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1725:ParameterNamesShouldMatchBaseDeclaration", MessageId = "0#")]
        public override void SetDuration(string time)
        {
            //PT00H05M00S
            String tHour = time.Substring(2, 2);
            String tMin = time.Substring(5, 2);
            String tSec = time.Substring(8, 2);
            Duration = new TimeSpan(Int32.Parse(tHour), Int32.Parse(tMin), Int32.Parse(tSec));
        }

        public override DateTime EndTime
        {
            get
            {
                return StartTime.Add(Duration);
            }
        }
    }
}
